﻿using EntityModel;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Api.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class UserController : ControllerBase
    {
        private readonly HallDbContext _DB;

        public UserController(HallDbContext context)
        {
            _DB =context;
        }
        [HttpGet]
        //public List<EntityUser> GetAllUser()
        //{
        //    return _DB.EntityUser.ToList();
        //}
        //public string? GetAllUser()
        //{
        //    return _DB.EntityUser.Where(w => w.FirstName == "张").Select(s => s.FirstName).FirstOrDefault();
        //}


      public Result GetAllUser()
        {
            var UserName = _DB.EntityUser.Where(w => w.FirstName == "张").Select(s => new
            {
                s.FirstName,
                s.LastNanme
            }).FirstOrDefault();

            Result result = new Result();
            result.Data = UserName;
            result.Code = 200;
            return result;
            
        }



        [HttpGet("{Id}")]
        public Result Get(Guid Id)
        {
            Result result = new Result();
            EntityUser? resultData = _DB.EntityUser.Where(w => w.Id == Id).FirstOrDefault<EntityUser>();
            if (resultData == null)
            {
                result.Code = 404;
            }
            else
            {
                result.Code = 200;
                result.Data = resultData;
            }
            return result;
        }
    }
}
